package com.oa.service.impl;

import com.oa.image.ImageUpload;
import com.oa.image.OfficeUpload;
import com.oa.image.UploadInterface;
import com.oa.service.FileService;
import com.oa.uitl.Base64Unitls;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class FileServiceImpl implements FileService {
    @Override
    public String upload(MultipartFile multipartFile, int type, Boolean isShear, Boolean isRotate, int fileUpload) throws IOException {
        UploadInterface uploadInterface= null;
        if (fileUpload==0){
            uploadInterface=new ImageUpload(multipartFile,type);
        }else {
            uploadInterface= new OfficeUpload(multipartFile);
        }
        return uploadInterface.upload(type,isShear,isRotate);
    }

    @Override
    public String upload(String base64, int type, Boolean isShear, Boolean isRotate, int fileUpload) throws IOException {
        MultipartFile file=Base64Unitls.getMultipartFile(base64);
        UploadInterface uploadInterface= null;
        if (fileUpload==0){
            uploadInterface= new ImageUpload(file,type);
        }else {
            uploadInterface= new OfficeUpload(file);
        }
        return uploadInterface.upload(type,isShear,isRotate);
    }
}
